package com.lczyfz.wisdom.modules.platform.wxutils;


import com.lczyfz.wisdom.modules.platform.constant.Constant;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

/**
 * Create by css on 2019/9/30
 */
public class CreateSignUtils {

    public static String compileParams(SortedMap<String,String> params){
        StringBuffer stringBuffer = new StringBuffer();
        Set set = params.entrySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            Map.Entry entry = (Map.Entry)iterator.next();
            String key = (String)entry.getKey();
            Object value = entry.getValue();
            if(null != value && !"".equals(value) && !"sign".equals(key) && !"".equals(key)){
                stringBuffer.append(key +"=" + value +"&");
            }
        }
        if(stringBuffer.length() > 0){
            stringBuffer.deleteCharAt(stringBuffer.length()-1);
        }
        return stringBuffer.toString();
    }

    public static String createSign(String characterEncoding,String paramStr){
        return MD5Util.MD5Encode(paramStr + "&key=" + Constant.getProperties().getProperty("keyCode"), characterEncoding).toUpperCase();
    }
}
